package com.winning.ds.role.controller;


import com.winning.ds.common.entity.SysQjcsEntity;
import com.winning.ds.common.entity.SysYyzcEntity;
import com.winning.ds.common.util.Common;
import com.winning.ds.common.util.ResponseEntity;
import com.winning.ds.role.service.ParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @program: plat
 * @description: 全局参数相关类
 * @author: nxs@winning.com.cn
 * @create: 2018-08-01 14:33
 **/
@RestController
@RequestMapping("/param")
public class ParamController {

    @Autowired
    private ParamService paramService;

    /**
     * 获取所属模块--根据应用代码
     *
     * @return   ResponseEntity
     */
    @RequestMapping(value = "/queryModule/{yydm}", method = RequestMethod.GET)
    public ResponseEntity getMenuTree(@PathVariable String yydm) {

        if (!Common.validateParams(yydm)) {
            return ResponseEntity.error(201, "无法获取应用编号");
        }
        List<SysQjcsEntity> list = paramService.queryMenuByAppid(yydm);
        return ResponseEntity.ok().put("list", list);
    }


    /**
     * 获取全局参数配置信息--根据应用代码和所属模块
     *
     * @return   ResponseEntity
     */
    @RequestMapping(value = "/queryParamList", method = RequestMethod.GET)
    public ResponseEntity getMenuTree(@RequestParam("yydm") String yydm,@RequestParam("ssmk") String ssmk,@RequestParam("csmc") String csmc) {

        if (!Common.validateParams(yydm)) {
            return ResponseEntity.error(201, "无法获取应用编号");
        }
        if (!Common.validateParams(ssmk)) {
            return ResponseEntity.error(201, "无法获取模块编号");
        }
        String  ssxt = yydm;
        List<SysQjcsEntity> list = paramService.queryParamList(ssxt, ssmk,csmc);
        return ResponseEntity.ok().put("list", list);
    }


    /**
     * 保存参数设置
     *
     * @return   ResponseEntity
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public ResponseEntity save(@RequestBody  Map<String, String> params) {

        if(params.size()>0)
        {
            paramService.saveParams(params);
        }else
        {
            return ResponseEntity.error(201, "无法获取参数");
        }
        return ResponseEntity.ok();
    }

    /**
     * 查询应用
     *
     * @return ResponseEntity
     */
    @RequestMapping(value = "/queryApplication", method = RequestMethod.GET)
    public ResponseEntity findRoleList() {
    List<SysYyzcEntity> list = paramService.queryApplication();
        return ResponseEntity.ok().put("list", list);
    }

    /**
     * 加密/解密数据库密码
     *
     * @return   ResponseEntity
     */
    @RequestMapping(value = "/updateDbPassWord", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public ResponseEntity updateDbPassWord(@RequestBody  Map<String, String> params) {

        if(params.size()>0)
        {
            paramService.updateDbPassWord(params);
        }else
        {
            return ResponseEntity.error(201, "无法获取参数");
        }
        return ResponseEntity.ok();
    }

}
